import requests
import json
url = "http://toy1.weather.com.cn/search"

name = input("请输入城市名称：")

params = {
    "cityname":name
}

r =  requests.get(url,params=params)
jsonString = r.text
# print(len(jsonString))
print(jsonString)
# print(jsonString[1:-1])
jsonString = jsonString[1:-1]
print(json.loads(jsonString))

print(json.loads(jsonString)[0]['ref'])

code = json.loads(jsonString)[0]['ref'].split("~")[0]
print(code)

